<!--
 * @Description: 底部第三个
 * @Author: Ronda
 * @Date: 2022-02-16 09:30:08
 * @LastEditors: Ronda
 * @LastEditTime: 2022-05-18 17:24:44
-->
<template>
  <div>
    <!-- 2.创建图表容器 -->
    <div ref="container" style="height:150px"></div>
  </div>
</template>

<script>
import { Line } from '@antv/g2plot';
import { get } from '@/utils/request'
import {mapState} from 'vuex'
// 1.引入momentjs commonjs 
let moment = require('moment');
export default {
  data() {
    return {
      tempData:[],
      linePlot:null
    };
  },
  computed:{
    // 映射公共数据
    ...mapState(['ed'])
  },
  watch:{
    // 监听设备变化
    async ed(){
      let res = await get('/dashboard/pageQueryData',{
        page:1,
        pageSize:50,
        engineer_id:this.ed.engineer_id,
        device_id: this.ed.device_id
      });
       res.data.list.forEach((item,index,arr) => {
        // (需要格式化的时间) (格式化时间的格式)
        item.insert_time = moment(item.insert_time).format('HH:mm');
        arr[0].temperature=15.4;
        // temp.push(arr[0],arr[19],arr[39],arr[59],arr[79],arr[99])
      });
      this.tempData = res.data.list;
      // 重新根据新数据绘制图表
      this.linePlot.changeData(this.tempData);
    }
  },
  methods: {
    async getTempData() {
      let res = await get('/dashboard/pageQueryData', {
        page: 1,
        pageSize: 30,
        engineer_id: 2,
        device_id: 1
      });
      // [{insert_time,tempature},{},{},{}]
      res.data.list.forEach((item,index,arr) => {
        // (需要格式化的时间) (格式化时间的格式)
        item.insert_time = moment(item.insert_time).format('HH:mm');
        arr[0].noise=58.3;
        // temp.push(arr[0],arr[19],arr[39],arr[59],arr[79],arr[99])
      });
      this.tempData = res.data.list;
      // this.loadCharts();
      // console.log(res,'获取响应');
      this.createPie();
    },
    createPie() {
    const linePlot = new Line(this.$refs.container, {
    data:this.tempData,
    xField: 'insert_time',
    yField: 'noise',
    stepType: 'noise',
});

  linePlot.render();
  this.linePlot=linePlot
    }
  },
  created() { },
  mounted() {
    // this.createPie()  
    this.getTempData()
  },
};
</script>
<style scoped></style>